//
//  SchoolCommentPicCollectionViewCell.swift
//  HoneyBee
//
//  Created by point on 2018/6/10.
//  Copyright © 2018年 point. All rights reserved.
//

import UIKit

protocol  SchoolCommentPicCollectionViewCellDelegate : class {
    func schoolCommentPicCollectionViewCellDelClick(btn:UIButton)
}



class SchoolCommentPicCollectionViewCell: UICollectionViewCell {
    weak var delegate: SchoolCommentPicCollectionViewCellDelegate?
    lazy var imgView:UIImageView =  UIImageView()
    fileprivate lazy var delBtn = UIButton(type: .custom)
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension SchoolCommentPicCollectionViewCell {
    
    @objc func clickBtn(btn:UIButton) {
        delegate?.schoolCommentPicCollectionViewCellDelClick(btn: btn)
    }
    
    func configModel(modelArr:[UIImage],index:IndexPath) {
        imgView.image = modelArr[index.item]
        delBtn.tag = index.item
        delBtn.isHidden = modelArr.count - 1 == index.item
    }
}


extension SchoolCommentPicCollectionViewCell {
    fileprivate func setupUI(){
        
        self.contentView.addSubview(imgView)
        self.contentView.addSubview(delBtn)
        imgView.backgroundColor = kColorC2
        
        delBtn.setBackgroundImage(UIImage(named: "icon_49"), for: .normal)
        
        imgView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
        contentView.backgroundColor = UIColor.white
        
        delBtn.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 30, height: 30))
            make.top.equalTo(contentView)
            make.right.equalTo(contentView)
        }
        delBtn.addTarget(self, action: #selector(clickBtn(btn:)), for: .touchUpInside)
        imgView.fastCornerRadius(value: 4)
    }
}
